﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Managers;
using RRRSRoguelikeData;
using System.Diagnostics;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Helpers.Visualizer;
using System.Drawing;

namespace RRRSRoguelike.Screens
{
    /// <summary>
    /// Manages the UI to enter Random Seed Number to start.
    /// </summary>
    class SeedScreen:Screen
    {
        
        Panel MainPanel;

        public SeedScreen()
        {
            PanelList.Add(new Panel(new Point(4, 3), 
                Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));
            MainPanel = PanelList[0];                    
        }

        #region Methods
        public override void Show()
        {
            Clear();

                this.MainPanel.Clear();
                this.MainPanel.Write(Properties.Strings.RequestSeed,0, ConsoleColor.White,TextAlignment.Multi);
                MainPanel.Draw();

                //we needs some robust error checking prevention here. grab first 5 characters then try catch?
                //we could also create a readline in the input manager or even a read number.
                int seed = GetSeedFromUser();

                this.MainPanel.Clear();    

                this.MainPanel.Write(Properties.Strings.LoadingSeed + Convert.ToString(seed),0, ConsoleColor.White,TextAlignment.Single);
                MainPanel.Draw();
                
                WaitKey();
                
                GameManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());

                GameManager.Instance.ScreenStack.Push(new VanillaDungeonScreen(seed));


        }

        private static int GetSeedFromUser()
        {
            int seed = 0;
            string input = Console.ReadLine();
            if (input.Length > 5) input =input.Remove(5);
            try
            {
                seed = Convert.ToInt32(input);
            }
            catch
            {
            	GameManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
                seed = GetSeedFromUser();
            }

            return seed;
        }
        #endregion
    }
}
